﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CXedu.WebSite.Code;
using System.Collections;
using CXedu.Model;
using CXedu.Business;
using Ajeelee.Core.Database;
using Ajeelee.Core.Utils;

namespace CXedu.WebSite.WebAdmin
{
    public partial class JoinList : AuthPageBase
    {
        protected string mname = "";
        protected string cateid;
        protected string content = "";
        protected int state = 0;
        Hashtable table = new Hashtable();
        protected IList<Student> studentList = new List<Student>();
        IStudentBusiness studentBll = new StudentBusinessFactory().CreateStudentBusiness();

        PageStructure ps = new PageStructure() { PageSize = 15, CurrPage = 1 };

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            try
            {
                mname = QueryParam("mname");
                content = QueryParam("content");
                cateid = QueryParam("cateid");
                state = QueryParamInt32("state");
                ps.CurrPage = QueryParamInt32("page", 1);

                // 删除
                if (!string.IsNullOrEmpty(QueryParam("d")) && QueryParamInt32("d") > 0)
                {
                    studentBll.Delete(QueryParamInt32("d"));
                }

                Hashtable handel = new Hashtable();
                // 处理
                if (!string.IsNullOrEmpty(QueryParam("h")) && QueryParamInt32("h") > 0)
                {
                    handel.Clear();
                    handel.Add(StudentHash.Id, QueryParamInt32("h"));
                    handel.Add(StudentHash.State, 2);
                    studentBll.UpdateSomeVal(handel);
                }
                // 不处理
                if (!string.IsNullOrEmpty(QueryParam("uh")) && QueryParamInt32("uh") > 0)
                {
                    handel.Clear();
                    handel.Add(StudentHash.Id, QueryParamInt32("uh"));
                    handel.Add(StudentHash.State, 1);
                    studentBll.UpdateSomeVal(handel);
                }

                table.Add(StudentHash.Name, Function.SafeSqlLiteral(mname));
                table.Add(StudentHash.Type, Function.SafeSqlLiteral(cateid));
                table.Add(StudentHash.Content, Function.SafeSqlLiteral(content));
                if (state > 0)
                {
                    table.Add(StudentHash.State, state);
                }
                table.Add(StudentHash.OrderField, "Time");
                studentList = studentBll.GetAllStudentByPage(table, ps);
                pager1.PageStruct = ps;
            }
            catch (System.Threading.ThreadAbortException ex) { }
            catch (Exception ex)
            {
                Function.WriteErrorLog(ex);
            }
        }
    }
}